{% extends "automan/template.html" %}
{% load staticfiles %}
{% block title %}应用列表{% endblock %}

{% block content %}
<div>
    <span class="l">
        {% if is_admin_group %}
        <a class="btn btn-primary radius" href="{% url 'appinput:create' %}">新建APP应用</a>
        {% endif %}
    </span>
    <span class="select-box inline r">
        {% include "automan/search.html" %}
    </span>
</div>
<br/><br/>

<table class="table table-border table-bordered table-bg">
    <thead>
        <th>APP应用组件</th>
        <th>Jenkins Job</th>
        <th>是否重启</th>
        <th>软件包名</th>
        <th>管理员</th>
        <th>编辑</th>
        <th>授权</th>
        <th>时间</th>
    </thead>
    <tbody>
        {% for item in object_list %}
        <tr class="text-l">
            <td>
                <span data-toggle="tooltip" data-placement="bottom" title="{{ item.description }}">
                    <a href="{% url 'appinput:detail' pk=item.id %}">{{ item.name }}</a>
                </span>
            </td>
            <td>{{ item.jenkins_job }}</td>
            <td>{{ item.is_restart_status }}</td>
            <td>
                <span class="label label-primary radius">
                    {{ item.package_name }}
                </span>
            </td>
            <td>{{ item.manage_user }}</td>
            <td>
                {% if is_admin_group %}
                <a href="{% url 'appinput:edit' pk=item.id %}">
                    <button class="btn btn-warning-outline radius">编辑</button>
                </a>
                {% else %}
                    {% ifequal request.user item.manage_user %}
                    <a href="{% url 'appinput:edit' pk=item.id %}">
                    <button class="btn btn-warning-outline radius">编辑</button>
                    </a>
                    {% else %}
                    <button class="btn disabled radius">编辑</button>
                    {% endifequal %}
                {% endif %}
            </td>
            <td>
                {% if is_admin_group %}
                <a href="{% url 'rightadmin:list' pk=item.id %}">
                    <button class="btn btn-warning-outline radius">授权</button>
                </a>
                {% else %}
                    {% ifequal request.user item.manage_user %}
                    <a href="{% url 'rightadmin:list' pk=item.id %}">
                    <button class="btn btn-warning-outline radius">授权</button>
                    </a>
                    {% else %}
                    <button class="btn disabled radius">授权</button>
                    {% endifequal %}
                {% endif %}
            </td>
            <td>{{ item.change_date }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
<br/>

<div class="text-r">
    <ul><li>
{#        <li>#}
            {% if page_obj.has_previous %}
                <a href="{{ current_url }}page={{ page_obj.previous_page_number }}" class="btn btn-primary-outline radius">上一页</a>
            {% else %}
                <a href="" class="btn btn-primary-outline radius">上一页</a>
            {% endif %}
{#        </li>#}
{#        <li>#}
            <a href="#">
                <span class="label label-primary radius">
                    {{ page_obj.number }}/{{ page_obj.paginator.num_pages }}
                </span>
            </a>
{#        </li>#}
{#        <li>#}
            {% if page_obj.has_next %}
                <a href="{{ current_url }}page={{ page_obj.next_page_number }}" class="btn btn-primary-outline radius">下一页</a>
            {% else %}
                <a href="" class="btn btn-primary-outline radius">下一页</a>
            {% endif %}
{#        </li>#}
    </li>
    </ul>
</div>
{% endblock %}

{% block script %}
<script>
$(".search_btn").click(function () {
    var search_pk = $("input[name='search_pk']").val() || "demo";
    if (search_pk == "demo") {
        $("body").Huimodalalert({content: "<span class='c-error'>请输入关键字再进行搜索！</span>", speed: 3000});
        return false;
    }
    search_pk = search_pk.replace(/(^\s*)|(\s*$)/g, "");
    var url = "{% url 'appinput:list' %}?search_pk=" + search_pk;
    console.log(url);
    location.href = url;
});
</script>
{% endblock %}